//
//  GradingTestSongAudioTableViewCell.h
//  CommunityNannyO2O
//
//  Created by apple on 15/8/13.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "GradingTestSongAudioTableViewCell.h"
#import "APIAdress.h"
#import "MBProgressHUD+YC.h"
#import "MJExtension.h"
#import "AccountTool.h"
#import "UIViewController+Create.h"
#import "CustomTextField.h"
#import "AppConfig.h"
#import "QXNetWorkTool.h"
#import "CommFunc.h"
#import "GradingTestSongAudioModel.h"
#import "NSString+Hash.h"

@interface GradingTestSongAudioTableViewCell()<QXNetWorkToolDelegate>


@property (weak, nonatomic) IBOutlet UIImageView *isDownload;


@end

@implementation GradingTestSongAudioTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"GradingTestSongAudioTableViewCell";
    GradingTestSongAudioTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        
        cell = [[[NSBundle mainBundle] loadNibNamed:ID owner:nil options:nil]firstObject];
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    
    return cell;
}

-(void)awakeFromNib

{
    
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    [self addGestureRecognizer:tapGestureRecognizer];
}


- (void)setTestSongAudioModel:(GradingTestSongAudioModel *)testSongAudioModel{
    
    _testSongAudioModel = testSongAudioModel;
    
    NSString *fileName = [NSString stringWithFormat:@"%@.mp3", [_testSongAudioModel.song_name  md5String]];
    
    NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
    
    NSString *filepath = [caches stringByAppendingPathComponent:fileName];
    
    NSFileManager *mgr = [NSFileManager defaultManager];
    
    if ([mgr fileExistsAtPath:filepath]) {
      
        _isDownload.hidden = NO;
        
        _testSongAudioModel.isDownload = NO;
        
    }else {
    
        _isDownload.hidden = YES;
    
        _testSongAudioModel.isDownload = YES;
        
    
    }
    
    if (self.isFromDown) {
        _isDownload.hidden = YES;

    }
    
}


-(void)tap
{
    if ([self.gradingTestSongAudioCellDelegate respondsToSelector:
         @selector(clickId:songModel:)]) {
        
        [self.gradingTestSongAudioCellDelegate clickId:self.songId songModel:_testSongAudioModel];
    }
}

-(int)getHeight
{
    int height = [CommFunc sizeWithString:self.detailLabel.text
                                     font:[UIFont fontWithName:@"Hiragino Sans GB" size:12]
                                      max:CGSizeMake(self.detailLabel.frame.size.width, MAXFLOAT)].height;
    
    if (height <= 0)
        return 80;
    else
    {
        height = self.detailLabel.frame.origin.y + height + 15;
        return height;
    }
    
    return 0;
}


@end




















